﻿#region Copyright Information
// // ****************************************************************
// // Feel free to extend or modify the code of the application to your needs. 
// // But remember do it for the Glory of our Lord Jesus Christ
// // ****************************************************************
#endregion
#region Usings

using System;
using System.Collections.Generic;
using System.Linq;
using Data;
using Interfaces.Persistence;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Persistence;

#endregion

namespace Tests.Persistence
{
	/// <summary>
	/// Summary description for UnitTest1
	/// </summary>
	[TestClass]
	public class Persistence
	{
		/// <summary>
		/// Private reference to <see cref="PersistenceManager"/>.
		/// </summary>
		private readonly IPersistanceManager p;

        /// <summary>
        /// The path to the song xml file.
        /// </summary>
        private readonly string songPath = @"D:\Song-Spot\res\Songs.xml";

		/// <summary>
		/// <see cref="Persistence"/> constructor.
		/// </summary>
		public Persistence()
		{
			p = new PersistenceManager(songPath);
		}

		/// <summary>
		/// Test GetAll songs method from <see cref="PersistenceManager"/>.
		/// </summary>
		[TestMethod]
		public void TestGetAllMethod()
		{
			Assert.IsTrue(p.GetAll().First().Name == "song1");
			Assert.IsTrue(p.GetAll().Last().Name == "song2");
		}

		/// <summary>
		/// Test GetSongByName songs method from <see cref="PersistenceManager"/>.
		/// </summary>
		[TestMethod]
		public void TestGetSongByNameMethod()
		{
			Assert.AreEqual(p.GetSongByName("song1").Name, "song1");
            //Assert.AreEqual(p.GetSongByName("song1").Id, Guid.Parse("A89B7F3F-94CD-41A6-85E5-9F0738AB6EAD"));
		}

		/// <summary>
		/// Test AddSong method from <see cref="PersistenceManager"/>.
		/// </summary>
		[TestMethod]
		public void TestAddSongMethod()
		{
			p.AddSong(new SongInfo(Guid.NewGuid(),"new song", null));
			Assert.AreEqual(p.GetAll().Count(), 3);
		}

		/// <summary>
		/// Test RemoveSong method from <see cref="PersistenceManager"/>.
		/// </summary>
		[TestMethod]
		public void TestRemoveSongMethod()
		{
			p.RemoveSong("song1");
			Assert.AreEqual(p.GetAll().Count(), 1);
		}

		/// <summary>
		/// Test UpdateSong method from <see cref="PersistenceManager"/>.
		/// </summary>
		[TestMethod]
		public void TestUpdateSongMethod()
		{
			var song = new SongInfo(Guid.NewGuid(), "song1", null);
			p.UpdateSong(song);
			Assert.IsTrue(p.GetAll().Contains(song));
		}

		/// <summary>
		/// Test Save method from <see cref="PersistenceManager"/>.
		/// </summary>
		[TestMethod]
		public void TestSaveMethod()
		{
            //p.AddSong(new SongInfo(Guid.NewGuid(), "new song",
            //                       new List<VerseInfo> { new VerseInfo(3, "someText", VerseType.Verse) }));
			p.Save(@"C:\Users\Home\Desktop\test.xml",
                new List<SongInfo>
                    {
                        new SongInfo(
                            Guid.Parse("A89B7F3F-94CD-41A6-85E5-9F0738AB6EAD"),
                            "song1",
                            new List<LyricInfo>{
                                new LyricInfo(
                                    1,
                                    new[] {"a", "b", "c"},
                                    VerseType.Verse)}),
                        new SongInfo(
                            Guid.NewGuid(),
                            "song2",
                            new List<LyricInfo>{
                                new LyricInfo(
                                    2,
                                    new[] {"a1", "b1", "c1"},
                                    VerseType.Verse)})
                    });
            Assert.IsTrue(true);
		}
	}
}